<template>
	<view class="forget winapp">
		<u-navbar title="修改密码" :autoBack="true" :bgColor="bgColor" leftIconColor="#fff" :titleStyle="titleStyle">
		</u-navbar>
		<view class="content">
			<!-- 主体 -->
			<view class="main">
				<view class="tips" style="padding-top:20px"></view>
				<!-- <wInput
					v-model="phoneData"
					type="text"
					maxlength="11"
					placeholder="请输入手机号码"
				></wInput> -->
				<wInput v-model="oldPassData" type="password" placeholder="请输入旧密码" isShowPass></wInput>
				<wInput v-model="newPassData" type="password" placeholder="请输入新密码" isShowPass></wInput>
				<wInput v-model="newPassData2" type="password" placeholder="请再次输入新密码" isShowPass>
				</wInput>
			</view>

			<wButton class="wbutton" text="重置密码" :rotate="isRotate" bgColor="#005495" @click.native="startRePass()"></wButton>

		</view>
	</view>
</template>

<script>
	let _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	export default {
		data() {
			return {
				titleStyle: {
					color: "#fff"
				},
				bgColor: '#005495',
				userid: '',
				seesionID: '',
				userDomainDtJson: '',
				oldPassData: '',
				newPassData2: '',
				newPassData: '',
				isRotate: false, //是否加载旋转
			}
		},
		components: {
			wInput,
			wButton
		},
		mounted() {
			_this = this;
			_this.baseUrl = _this.$store.getters.getBaseUrl
			//this.isLogin();
		},
		methods: {
			startRePass() {
				//重置密码
				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.newPassData !== this.newPassData2) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '新密码错误'
					});
					return false;
				}
				if (this.newPassData === this.oldPassData) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '新旧密码不可相同'
					});
					return false;
				}
				this.ajaxSavePassWord()
			},
			ajaxSavePassWord() {
				_this.isRotate = true
				_this.http({
					url: _this.baseUrl + '/ChangePassword',
					method: 'post',
					data: {
						userid: _this.userid,
						corp: '',
						domain: '',
						seesionID: _this.seesionID,
						passwordOld: _this.oldPassData,
						passwordNew: _this.newPassData,
						userDomainDtJson: _this.userDomainDtJson
					},
					success: e => {
						_this.isRotate = false
						console.log(e)
						if (e.d.resultCode === "100000") {
							uni.showToast({
								icon: 'none',
								position: 'bottom',
								title: '修改密码成功'
							});
							uni.navigateBack()
							return
						}
						if (e.d.resultCode !== '100000') {
							uni.showToast({
								icon: 'none',
								title: e.d.resultMsg
							})
							return
						}
					},
					fail: e => {
						console.log('fali');
					}
				});
			}
		},
		onLoad: function(option) {
			let _this = this;
			let userMsg = JSON.parse(option.data)
			console.log(JSON.parse(option.data));
			_this.userid = option.name
			_this.seesionID = userMsg.seesionID
			_this.userDomainDtJson = JSON.stringify(userMsg.userDomain)
			// if (!_this.$u.test.isEmpty(option.data)) {
				
			// 	return;
			// }
		},

	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
	@import url("../../static/css/base.css");
</style>
